//
//  ShareHandle.swift
//  MYSwift
//
//  Created by wangshuguan on 16/8/16.
//  Copyright © 2016年 wangshuguan. All rights reserved.
//

import UIKit

class ShareHandle {
    
    lazy var pinyin:[String:String]? = {
        return Dictionary.path(with: Bundle.main.path(forResource: "pinyin", ofType: "plist")!)
    }()
    var writeLog = false
    static var shared : ShareHandle = {
        return ShareHandle()
    }()
}
extension Character{
    var pinyin:String{
        get{
            return ShareHandle.shared.pinyin!["\((unicodeScalars.first?.value)!)"] ?? "\(self)"
        }
    }
}
extension String{
    func pinyinLetter() -> String {
        return pinyin.isEmpty ? "#" : pinyin.capitalized[0..<1]
    }
    var pinyin:String {
        get{
            return reduce("",{$0+$1.pinyin})
        }
    }
    var pinyinTitle:String {
        get{
            return reduce("",{$0+$1.pinyin[0..<1]})
        }
    }
}

